package net.qqxh.controller;


import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;


@RequestMapping("/oauth2")

@Controller
public class Oauth2Controller {
    String clientId = "88VXLxVv1Gjuj0MsO3i5bSUn";
    String redirectUrl = "/oauth2/requestServerToken";
    String authorizecodeurl = "http://openapi.baidu.com/oauth/2.0/authorize";

    @RequestMapping("/login")
    public String oauth2login(HttpServletRequest request) {
        String projectPath = request.getScheme()+"://"+ request.getServerName() + ":" + request.getServerPort() + request.getContextPath();
        String redirct = projectPath + redirectUrl;
        String redirect = authorizecodeurl + "?client_id=" + clientId + "&redirect_uri=" + redirct + "&response_type=code";
        return "redirect:" + redirect;
    }
/*
    *//**
     * 获取token
     *
     * @param code
     * @return
     * @throws
     *//*
    @RequestMapping("/requestServerToken")
    public String requestServerFirst(@RequestParam(name = "code") String code) throws OAuthProblemException {
        Subject subject = SecurityUtils.getSubject();
        OAuth2Token oAuth2Token = new OAuth2Token(code);
        oAuth2Token.setPrincipal(code);
        subject.login(oAuth2Token);
        if (subject.isAuthenticated()) {
            return "redirect:/";
        } else {
            return "redirect:/login";
        }

    }*/

}
